package com.zwk.views;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import com.zwk.dao.WKAttendance;
import com.zwk.dao.WKAttendanceRecord;
import com.zwk.model.WKAttendanceOperator;
import com.zwk.model.WKStdLoginOperator;
import com.zwk.model.WKTchOperator;
import com.zwk.views.*;

public class WKInputStdView extends JFrame{
 
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 300;
	private static final int DEFAULT_HEIGHT = 300;
	public static JFrame frame;
	JFrame parentFrame;
	public WKInputStdView(String id) {
		frame = new JFrame();
		frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		frame.setTitle("学生考勤信息录入");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenWidthpx = screenSize.width;
		int screenHeightpx = screenSize.height;
		frame.setLocation(screenWidthpx / 3, screenHeightpx / 3);
		frame.setLocationByPlatform(false);
		
		Image image = new ImageIcon(this.getClass().getResource("/WKImage/top1.jpg")).getImage();
		frame.setIconImage(image);
		
		WKInputStdPanel loginPanel = new WKInputStdPanel(id);
		frame.setContentPane(loginPanel);
		frame.setLayout(null);
		frame.setVisible(true);
		
	}
	private class WKInputStdPanel extends JPanel {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		JLabel picLabel;
	    JLabel numLabel;
	    JComboBox numComboBox;
	    JLabel claLabel;
	    JTextField claTextField;
	    JLabel idLabel;
	    JComboBox idComboBox;
	    JLabel nameLabel;
	    JTextField nameTextField;
	    JLabel timeLabel;
	    JTextField timeTextField;
	    JLabel attendLabel;
	    JComboBox attendComboBox;
	    
	    JButton backButton, inputButton;
	    JPanel buttonPanel, infoPanel;
	    
	    public WKInputStdPanel(final String id) {
	    	final WKAttendance attendance = new WKAttendance();
	    	final WKAttendanceRecord record = new WKAttendanceRecord();
	    	infoPanel = new JPanel(); 
	    	infoPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
	    	infoPanel.setBounds(0, 0, 300, 240);
	    	picLabel = new JLabel();
	    	picLabel.setSize(300, 40);
	    	ImageIcon image = new ImageIcon(this.getClass().getResource("/WKImage/top1.jpg"));
	    	image.setImage(image.getImage().getScaledInstance(picLabel.getWidth(), picLabel.getHeight(), Image.SCALE_DEFAULT));;
	    	picLabel.setIcon(image);
	    	numLabel = new JLabel("教学班号:");
	    	DefaultComboBoxModel num = new DefaultComboBoxModel();
		    num.addElement("1003");
		    num.addElement("1004");
		    num.addElement("1005");
		    num.addElement("1006");
		    numComboBox = new JComboBox(num);
		    numComboBox.setSize(200, 20);
	    	numComboBox.setSelectedIndex(0);
	    	numComboBox.setPreferredSize(new Dimension(195, 18));
	    	claLabel = new JLabel("课程名称:");
	    	claTextField = new JTextField(15);
	    	idLabel = new JLabel("学 生  ID:");
	    	DefaultComboBoxModel cbm = new DefaultComboBoxModel();
		    cbm.addElement("2014213915");
		    cbm.addElement("2014213916");
		    cbm.addElement("2014213917");
		    cbm.addElement("2014213918");
		    idComboBox = new JComboBox(cbm);
	    	idComboBox.setSelectedIndex(0);
	    	idComboBox.setPreferredSize(new Dimension(195, 20));
	    	nameLabel = new JLabel("学生姓名:");
	    	nameTextField = new JTextField(15);
	    	timeLabel = new JLabel("考勤时间:");
	    	timeTextField = new JTextField(15);
	    	attendLabel = new JLabel("考勤记录:");
	    	DefaultComboBoxModel attend = new DefaultComboBoxModel();
		    attend.addElement("正常");
		    attend.addElement("迟到");
		    attend.addElement("旷课");
		    attend.addElement("请假");
		    attendComboBox = new JComboBox(attend);
	    	attendComboBox.setSelectedIndex(0);
	    	attendComboBox.setPreferredSize(new Dimension(195, 20));
	    	infoPanel.add(picLabel);
	    	infoPanel.add(numLabel);
	    	infoPanel.add(numComboBox);
	    	infoPanel.add(claLabel);
	    	infoPanel.add(claTextField);
	    	infoPanel.add(idLabel);
	    	infoPanel.add(idComboBox);
	    	infoPanel.add(nameLabel);
	    	infoPanel.add(nameTextField);
	    	infoPanel.add(timeLabel);
	    	infoPanel.add(timeTextField);
	    	infoPanel.add(attendLabel);
	    	infoPanel.add(attendComboBox);
	    	add(infoPanel, BorderLayout.CENTER);
	    	
	    	buttonPanel = new JPanel();
	    	buttonPanel.setBounds(0, 240, 300, 40);
	    	inputButton = new JButton("录入考勤信息");
	    	inputButton.addActionListener(new ActionListener() {
	    		@SuppressWarnings("deprecation")
				@Override
	    		public void actionPerformed(ActionEvent e) {
	    			
	    			attendance.setClassId((String)numComboBox.getSelectedItem());
	    			attendance.setTime(timeTextField.getText());		
		    		attendance.setId("9528");
		    		record.setAttendanceId("9528");
		    		record.setAttendanceState((String)attendComboBox.getSelectedItem());
		    		record.setRecord(timeTextField.getText());
		    		record.setStudentId((String)idComboBox.getSelectedItem());
		    		WKAttendanceOperator OP = new WKAttendanceOperator();
		    		OP.inputInfo(attendance, record);
		      }
	    	});
	    	backButton = new JButton("返回上级菜单");
	    	backButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKTchFuncPortalFrame stdView = new WKTchFuncPortalFrame(id);
	    			frame.dispose();
	    		}
	    	});
	    	buttonPanel.add(inputButton);
	    	buttonPanel.add(backButton);
	    	add(buttonPanel, BorderLayout.SOUTH);
	    }
	
	}
	
}
